<template>
  <!-- hvps111明细-->
  <el-dialog :title="title" center :visible.sync="openState" width="1024px" :close-on-click-modal="false">
    <card-form
      ref="cardForm"
      :allDisabled="true"
      :title="title"
      :openState="openState"
      :dictMap="dictMap"
      :cardList="cardList"
      :formData="form"
    ></card-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="approve">复核</el-button>
      <el-button @click="reject">拒绝</el-button>
      <el-button @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { detailCheck2, approve2, reject2 } from "@/api/cnaps/baseBiz/send/check/creditCheck";
import CardForm from "@/views/components/CardForm";

export default {
  name: "Details",
  components: {
    CardForm,
  },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      cardList: [],
      busTypeList: [],
      id: "",
      title: "",
      msgType: "",
      // 是否显示弹出层
      openState: false,
      // 表单参数
      form: {
        amount: "0.00",
      },
    };
  },
  watch: {
    dictMap: {
      handler(data) {},
    },
  },
  async mounted() {
    let that = this;
  },
  methods: {
    // 表单重置
    reset() {
      // this.resetForm("editForm");
      this.$set(this, "form", {});
    },
    close() {
      this.openState = true;
    },
    // 关闭回掉
    handleClose() {
      this.openState = false;
    },
    show(id = "", msgType = "") {
      let that = this;
      this.msgType = msgType;
      this.id = id;
      this.title = "小额借记业务复核";
      if (id) {
        // 如果传了ID 这里查询一个已经存在的数据
        detailCheck2({
          coreId: this.id,
          msgType: this.msgType,
        }).then((res) => {
          res.result.payerBrno = "";
          res.result.payeeBrno = "";
          let tempForm = res.result;
          this.$set(this, "form", tempForm);
          let code = tempForm.bizTypeCode;
          let formConfigList = [
            {
              name: "交易基础信息",
              ref: "baseInfo",
              rules: {
                amount: [
                  {
                    required: true,
                    message: "请输入金额",
                  },
                ],
              },
              rowColNum: 3,
              labelWidth: "100px",
              hide: false,
              formItemList: [
                {
                  type: "input",
                  prop: "id",
                  defaultAttr: {
                    label: "交易流水号",
                    placeholder: "请填写交易流水号",
                  },
                },
                {
                  type: "input",
                  prop: "vdate",
                  defaultAttr: {
                    label: "CPG日期",
                    placeholder: "请填写CPG日期",
                  },
                },
                {
                  type: "input",
                  prop: "workdate",
                  defaultAttr: {
                    label: "工作日期",
                    placeholder: "请填写工作日期",
                  },
                },
                {
                  type: "dict",
                  dict: "BIZ_TYPE_111",
                  prop: "bizTypeCode",
                  defaultAttr: {
                    label: "业务类型",
                    placeholder: "请选择业务类型",
                  },
                },
                {
                  type: "select",
                  prop: "bizCtgyCode",
                  defaultAttr: {
                    label: "业务种类",
                    placeholder: "请选择业务种类",
                  },
                  selectOptionList: this.busTypeList.map((x) => {
                    return { label: x.text, value: x.value };
                  }),
                },
                {
                  type: "dict",
                  dict: "CBFLAG",
                  prop: "cbflag",
                  defaultAttr: {
                    label: "记账标识",
                    placeholder: "请选择记账标识",
                  },
                },
                {
                  type: "input",
                  prop: "bizRtrltd",
                  defaultAttr: {
                    label: "回执期限",
                    placeholder: "请填写回执期限",
                  },
                },
                {
                  type: "dict",
                  dict: "CUST_FLAG1",
                  prop: "custflag1",
                  defaultAttr: {
                    label: "账户类型",
                    placeholder: "请选择账户类型",
                  },
                },
                {
                  type: "input",
                  prop: "transCNY",
                  defaultAttr: {
                    label: "交易币种",
                    placeholder: "请填写交易币种",
                    disabled: true,
                    defaultValue: "CNY",
                  },
                },
                {
                  type: "input",
                  prop: "contractNo",
                  defaultAttr: {
                    label: "合同协议号",
                    placeholder: "请填写合同协议号",
                  },
                },
                {
                  type: "number",
                  prop: "amount",
                  defaultAttr: {
                    label: "现金金额",
                    placeholder: "请填写现金金额",
                    disabled: false,
                  },
                  linkedRules: [
                    {
                      ruleType: "callbackFn",
                      callback: (item, form, formListOptions, rowData, initFlag, formDiarules) => {
                        if (that.$refs.cardForm) {
                          that.$refs.cardForm.$refs["upperAmount"][0].changeAmount(form[item.prop]);
                        }
                      },
                    },
                  ],
                },
                {
                  type: "slot",
                  prop: "upperAmount",
                  componentType: "HtAmountUpper",
                  ref: "upperAmount",
                  defaultAttr: {
                    label: "大写金额",
                  },
                },
              ],
            },
            {
              name: "付款人信息",
              ref: "payerInfo",
              rules: {
                payerActno: [
                  {
                    required: true,
                    message: "请填写付款人账号",
                  },
                ],
              },
              rowColNum: 4,
              labelWidth: "110px",
              hide: false,
              formItemList: [
                {
                  type: "input",
                  prop: "payerActno",
                  defaultAttr: {
                    label: "付款人账号",
                    placeholder: "请填写付款人账号",
                    colWidthCount: 2,
                    disabled: false,
                    defaultValue: "",
                  },
                },
                {
                  type: "input",
                  prop: "payerName",
                  defaultAttr: {
                    label: "付款人名称",
                    placeholder: "请填写付款人名称",
                    colWidthCount: 4,
                  },
                },
                {
                  type: "input",
                  prop: "payerAddr",
                  defaultAttr: {
                    label: "付款人地址",
                    placeholder: "请填写付款人地址",
                    colWidthCount: 4,
                  },
                },
                {
                  type: "input",
                  prop: "payerBrno",
                  defaultAttr: {
                    label: "付款行行号",
                    placeholder: "请填写付款行行号",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "payerBrname",
                  defaultAttr: {
                    label: "付款行行名",
                    placeholder: "请填写付款行行名",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "payerAccBrno",
                  defaultAttr: {
                    label: "付款人开户行号",
                    placeholder: "请填写付款人开户行号",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "payerAccBrname",
                  defaultAttr: {
                    label: "付款人开户行行名",
                    placeholder: "请填写付款人开户行行名",
                    colWidthCount: 2,
                  },
                },
              ],
            },
            {
              name: "收款人信息",
              ref: "payeeInfo",
              rules: {
                payeeActno: [
                  {
                    required: true,
                    message: "请填写收款人账号",
                  },
                ],
                payeeBrno: [
                  {
                    required: true,
                    message: "请填写收款行行号",
                  },
                ],
              },
              rowColNum: 4,
              labelWidth: "110px",
              hide: false,
              formItemList: [
                {
                  type: "input",
                  prop: "payeeActno",
                  defaultAttr: {
                    label: "收款人账号",
                    placeholder: "请填写收款人账号",
                    colWidthCount: 2,
                    disabled: false,
                  },
                },
                {
                  type: "input",
                  prop: "payeeName",
                  defaultAttr: {
                    label: "收款人名称",
                    placeholder: "请填写收款人名称",
                    colWidthCount: 4,
                  },
                },
                {
                  type: "input",
                  prop: "payeeAddr",
                  defaultAttr: {
                    label: "收款人地址",
                    placeholder: "请填写收款人地址",
                    colWidthCount: 4,
                  },
                },
                {
                  type: "input",
                  prop: "payeeBrno",
                  defaultAttr: {
                    label: "收款行行号",
                    placeholder: "请填写收款行行号",
                    colWidthCount: 2,
                    disabled: false,
                  },
                },
                {
                  type: "input",
                  prop: "payeeBrname",
                  defaultAttr: {
                    label: "收款行行名",
                    placeholder: "请填写收款行行名",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "payeeAccBrno",
                  defaultAttr: {
                    label: "收款人开户行号",
                    placeholder: "请填写付款人开户行号",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "payeeAccBrname",
                  defaultAttr: {
                    label: "收款人开户行行名",
                    placeholder: "请填写收款人开户行行名",
                    colWidthCount: 2,
                  },
                },
              ],
            },
            {
              name: "其他交易信息",
              ref: "otherInfo",
              rules: {},
              rowColNum: 4,
              labelWidth: "110px",
              hide: false,
              formItemList: [
                {
                  type: "input",
                  prop: "agency1",
                  defaultAttr: {
                    label: "中介机构1",
                    placeholder: "请填写中介机构1",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "agency1name",
                  defaultAttr: {
                    label: "中介机构1名称",
                    placeholder: "请填写中介机构1名称",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "agency2",
                  defaultAttr: {
                    label: "中介机构2",
                    placeholder: "请填写中介机构2",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "agency2name",
                  defaultAttr: {
                    label: "中介机构2名称",
                    placeholder: "请填写中介机构2名称",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "textarea",
                  prop: "remarks",
                  defaultAttr: {
                    label: "备注",
                    placeholder: "请填写备注",
                    colWidthCount: 4,
                  },
                },
                {
                  type: "textarea",
                  prop: "memo",
                  defaultAttr: {
                    label: "附言",
                    placeholder: "请填写附言",
                    colWidthCount: 4,
                  },
                },
              ],
            },
            {
              name: "委托收款 （划回）",
              ref: "entrustInfo",
              rules: {},
              rowColNum: 9,
              labelWidth: "100px",
              hide: !(code === "A109"),
              formItemList: [
                {
                  type: "date",
                  prop: "clltnNotesDate",
                  defaultAttr: {
                    label: "票据日期",
                    placeholder: "请填写票据日期",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "clltnNotesType",
                  defaultAttr: {
                    label: "凭证种类",
                    placeholder: "请填写凭证种类",
                    colWidthCount: 3,
                  },
                },
              ],
            },
            {
              name: "托收承付 （划回）",
              ref: "prepayment",
              rules: {},
              rowColNum: 9,
              labelWidth: "100px",
              hide: !(code === "A110"),
              formItemList: [
                {
                  type: "date",
                  prop: "clltnNotesDate",
                  defaultAttr: {
                    label: "票据日期",
                    placeholder: "请填写票据日期",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "pmtPayAmount",
                  defaultAttr: {
                    label: "支付金额",
                    placeholder: "请填写支付金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "pmtOriAmount",
                  defaultAttr: {
                    label: "原托金额",
                    placeholder: "请填写原托金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "pmtRejectAmount",
                  defaultAttr: {
                    label: "拒付金额",
                    placeholder: "请填写拒付金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "pmtAmendsAmount",
                  defaultAttr: {
                    label: "赔偿金额",
                    placeholder: "请填写赔偿金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "pmtAddAmount",
                  defaultAttr: {
                    label: "多付金额",
                    placeholder: "请填写多付金额",
                    colWidthCount: 3,
                  },
                },
              ],
            },
            {
              name: "商业汇票附加域信息",
              ref: "commercialDraft",
              rules: {},
              rowColNum: 9,
              labelWidth: "100px",
              hide: !(code === "A111"),
              formItemList: [
                {
                  type: "input",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "申请人账号",
                    placeholder: "请填写申请人账号",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "dftAppName",
                  defaultAttr: {
                    label: "申请人名称",
                    placeholder: "请填写申请人名称",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "date",
                  prop: "dftDate",
                  defaultAttr: {
                    label: "票据日期",
                    placeholder: "请填写票据日期",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "出票金额",
                    placeholder: "请填写出票金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "dftStAmt",
                  defaultAttr: {
                    label: "实际结算金额",
                    placeholder: "请填写实际结算金额",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "number",
                  prop: "dftOverAmt",
                  defaultAttr: {
                    label: "多余金额",
                    placeholder: "请填写多余金额",
                    colWidthCount: 3,
                  },
                },
              ],
            },
            {
              name: "跨境支付附加域信息",
              ref: "crossPayment",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              hide: !(code === "A113"),
              formItemList: [
                {
                  type: "date",
                  prop: "cbBizAssocBizDate",
                  defaultAttr: {
                    label: "关联业务委托日期",
                    placeholder: "请填写关联业务委托日期",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "cbBizFeeCode",
                  defaultAttr: {
                    label: "费用编码",
                    placeholder: "请填写费用编码",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "cbBizSndBnkFee",
                  defaultAttr: {
                    label: "发报行的收费",
                    placeholder: "请填写发报行的收费",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "payAddInfo",
                  defaultAttr: {
                    label: "收报行的收费",
                    placeholder: "请填写收报行的收费",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "textarea",
                  prop: "cbBizRemark",
                  defaultAttr: {
                    label: "跨境业务附言",
                    placeholder: "请填写跨境业务附言",
                    colWidthCount: 6,
                  },
                },
              ],
            },
            {
              name: "支票附加域信息",
              ref: "cheque",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              hide: !(code === "A201"),
              formItemList: [
                {
                  type: "date",
                  prop: "checkNotesDate",
                  defaultAttr: {
                    label: "出票日期",
                    placeholder: "请填写出票日期",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "checkAppName",
                  defaultAttr: {
                    label: "出票人名称",
                    placeholder: "请填写出票人名称",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "checkNotesNum",
                  defaultAttr: {
                    label: "票据张数",
                    placeholder: "请填写票据张数",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "checkNotesAmount",
                  defaultAttr: {
                    label: "票据金额",
                    placeholder: "请填写票据金额",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "checkExchage",
                  defaultAttr: {
                    label: "牌价",
                    placeholder: "请填写牌价",
                    colWidthCount: 2,
                  },
                },
              ],
            },
            {
              name: "汇票资金移存附加域信息",
              ref: "draft",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              hide: !(code === "A202"),
              formItemList: [
                {
                  type: "date",
                  prop: "checkNotesDate",
                  defaultAttr: {
                    label: "出票日期",
                    placeholder: "请填写出票日期",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftKey",
                  defaultAttr: {
                    label: "汇票密押",
                    placeholder: "请填写汇票密押",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftCtgy",
                  defaultAttr: {
                    label: "票据种类",
                    placeholder: "请填写票据种类",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftPayBrno",
                  defaultAttr: {
                    label: "现金汇票兑付行",
                    placeholder: "请填写现金汇票兑付行",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftPayerName",
                  defaultAttr: {
                    label: "收款人名称",
                    placeholder: "请填写票面记载的收款人名称",
                    colWidthCount: 6,
                  },
                },
              ],
            },
            {
              name: "银行汇票附加域信息",
              ref: "bankDraft",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              hide: !(code === "A203"),
              formItemList: [
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "date",
                  prop: "checkNotesDate",
                  defaultAttr: {
                    label: "出票日期",
                    placeholder: "请填写出票日期",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "申请人账号",
                    placeholder: "请填写申请人账号",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftAppName",
                  defaultAttr: {
                    label: "申请人名称",
                    placeholder: "请填写申请人名称",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "出票金额",
                    placeholder: "请填写出票金额",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftStAmt",
                  defaultAttr: {
                    label: "实际结算金额",
                    placeholder: "请填写实际结算金额",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftOverAmt",
                  defaultAttr: {
                    label: "多余金额",
                    placeholder: "请填写多余金额",
                    colWidthCount: 2,
                  },
                },
              ],
            },
            {
              name: "银行本票附加域信息",
              ref: "bankSelfDraft",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              hide: !(code === "A204"),
              formItemList: [
                {
                  type: "input",
                  prop: "e2eId",
                  defaultAttr: {
                    label: "票据号码",
                    placeholder: "请填写票据号码",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "date",
                  prop: "checkNotesDate",
                  defaultAttr: {
                    label: "出票日期",
                    placeholder: "请填写出票日期",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "申请人账号",
                    placeholder: "请填写申请人账号",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftCtgy",
                  defaultAttr: {
                    label: "票据种类",
                    placeholder: "请填写票据种类",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "input",
                  prop: "dftAppName",
                  defaultAttr: {
                    label: "申请人名称",
                    placeholder: "请填写申请人名称",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftAppActno",
                  defaultAttr: {
                    label: "出票金额",
                    placeholder: "请填写出票金额",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftStAmt",
                  defaultAttr: {
                    label: "实际结算金额",
                    placeholder: "请填写实际结算金额",
                    colWidthCount: 2,
                  },
                },
                {
                  type: "number",
                  prop: "dftOverAmt",
                  defaultAttr: {
                    label: "多余金额",
                    placeholder: "请填写多余金额",
                    colWidthCount: 2,
                  },
                },
              ],
            },
            {
              name: "复核信息",
              ref: "check",
              rules: {},
              rowColNum: 6,
              labelWidth: "110px",
              formItemList: [
                {
                  type: "input",
                  prop: "mdTlrno",
                  defaultAttr: {
                    label: "录入操作员",
                    placeholder: "请填写录入操作员",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "input",
                  prop: "mdTime",
                  defaultAttr: {
                    label: "录入时间",
                    placeholder: "请填写录入时间",
                    colWidthCount: 3,
                  },
                },
                {
                  type: "textarea",
                  prop: "ckRemarks",
                  defaultAttr: {
                    label: "复核附言",
                    placeholder: "请填写复核附言",
                    colWidthCount: 6,
                    disabled: false,
                  },
                },
              ],
            },
          ];
          this.cardList = formConfigList;
          this.openState = true;
        });
      }
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", false);
    },
    getReqCode() {
      console.log(this.msgType);
      let code = "";
      if (this.msgType === "beps.133.001.01") {
        code = "5008";
      } else if (this.msgType === "beps.127.001.01") {
        code = "5007";
      }
      return code;
    },
    /** TODO提交按钮 */
    approve: function () {
      let formData = this.$refs.cardForm.getFormData();
      console.log("formData", formData);
      //如果有ID 则是修改
      if (this.id) {
        formData.id = this.id;
        approve2(formData, this.getReqCode()).then((res) => {
          this.msgSuccess("复核成功");
          this.$emit("editComplete", true);
          this.openState = false;
        });
      }
    },
    reject() {
      let formData = this.$refs.cardForm.getFormData();
      formData.id = this.id;
      reject2(formData, this.getReqCode()).then((res) => {
        this.msgSuccess("拒绝成功");
        this.$emit("editComplete", true);
        this.openState = false;
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
